package com.yx.modules.api.config;

import com.yx.common.interceptor.AuthorizationInterceptor2;
import com.yx.common.resolver.LoginUserHandlerMethodArgumentResolver2;
import com.yx.modules.api.interceptor.AuthorizationInterceptor;
import com.yx.modules.api.resolver.LoginUserHandlerMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/** MVC配置
 * Created by wuye on 2017/11/24.
 */
@Configuration
public class WebMvcConfigApi extends WebMvcConfigurerAdapter {
    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;
    @Autowired
    private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver;

    @Autowired
    private AuthorizationInterceptor2 authorizationInterceptor2;

    @Autowired
    private LoginUserHandlerMethodArgumentResolver2 loginUserHandlerMethodArgumentResolver2;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**","/pc/**");
        registry.addInterceptor(authorizationInterceptor2).addPathPatterns("/sys/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(loginUserHandlerMethodArgumentResolver);
        argumentResolvers.add(loginUserHandlerMethodArgumentResolver2);
    }
}
